﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LabelPrintSystem
{
    public partial class FrmUncheckConfig : Form
    {
        private ClsConfig m_cofing;
        public FrmUncheckConfig(ClsConfig config)
        {
            InitializeComponent();
            m_cofing = config;
            iniConfig();
        }

        void iniConfig()
        {
            cb_SetModule.SelectedIndex = m_cofing.setModule;

            chk_uPIM.Checked = m_cofing.isuPIM;
            chk_uElectric.Checked = m_cofing.isuElectric;
            chk_uRCU.Checked = m_cofing.isuRcu;

            nud_reform.Value = m_cofing.numReform;
            nud_uPIM.Value = m_cofing.numPIM;
            nud_uElectric.Value = m_cofing.numElectric;
            nud_uRCU.Value = m_cofing.numRcu;
        }

        void ctl_Enable(bool isReform = false, bool isUncheck = false, int value = 0)
        {
            pnl_reform.Enabled = isReform;
            nud_reform.Value = value;

            gb_uCheck.Enabled =
            chk_uPIM.Checked =
            chk_uElectric.Checked =
            chk_uRCU.Checked = isUncheck;
            nud_uPIM.Value =
            nud_uElectric.Value =
            nud_uRCU.Value = value;
        }

        private void cb_isUncheckModule_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cb_SetModule.SelectedIndex)
            {
                case 0:
                    ctl_Enable();
                    break;
                case 1:
                    ctl_Enable(true, false);
                    break;
                case 2:
                    ctl_Enable(false, true);
                    break;
            }
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            if (cb_SetModule.SelectedIndex == 1 && (int)nud_reform.Value == 0)
            {
                MessageBox.Show("改造数量必须大于0！");
                return;
            }
            if (chk_uPIM.Checked && (int)nud_uPIM.Value == 0)
            {
                MessageBox.Show("交调免测数量必须大于0！");
                return;
            }
            if (!chk_uPIM.Checked)
            {
                nud_uPIM.Value = 0;
            }
            if (chk_uElectric.Checked && (int)nud_uElectric.Value == 0)
            {
                MessageBox.Show("电性能免测数量必须大于0！");
                return;
            }
            if (!chk_uElectric.Checked)
            {
                nud_uElectric.Value = 0;
            }
            if (chk_uRCU.Checked && (int)nud_uRCU.Value == 0)
            {
                MessageBox.Show("RCU免测数量必须大于0！");
                return;
            }
            if (!chk_uRCU.Checked)
            {
                nud_uRCU.Value = 0;
            }
            m_cofing.setModule = cb_SetModule.SelectedIndex;
            m_cofing.isuPIM = chk_uPIM.Checked;
            m_cofing.isuElectric = chk_uElectric.Checked;
            m_cofing.isuRcu = chk_uRCU.Checked;
            m_cofing.numReform = (int)nud_reform.Value;
            m_cofing.numPIM = (int)nud_uPIM.Value;
            m_cofing.numElectric = (int)nud_uElectric.Value;
            m_cofing.numRcu = (int)nud_uRCU.Value;



            this.DialogResult = DialogResult.OK;
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void chk_uPIM_CheckedChanged(object sender, EventArgs e)
        {
            if (!chk_uPIM.Checked) { nud_uPIM.Value = 0; }
        }

        private void chk_uElectric_CheckedChanged(object sender, EventArgs e)
        {
            if (!chk_uElectric.Checked) { nud_uElectric.Value = 0; }
        }

        private void chk_uRCU_CheckedChanged(object sender, EventArgs e)
        {
            if (!chk_uRCU.Checked) { nud_uRCU.Value = 0; }
        }


    }
}
